class rotate_array:
    def rotate(self, nums: list[int], k: int) -> None:
        raise NotImplementedError


class solution1(rotate_array):
    def rotate(self, nums: list[int], k: int) -> None:
        n = len(nums)
        arr = [0] * n
        for i in range(n):
            arr[(i + k) % n] = nums[i]
        for i in range(n):
            nums[i] = arr[i]


class solution2(rotate_array):
    def rotate(self, nums: list[int], k: int) -> None:
        n = len(nums)
        k %= n
        count = self.gcb(n, k)
        for i in range(count):
            curr_idx = i
            curr = nums[curr_idx]
            while True:
                next_idx = (curr_idx + k) % n
                temp = nums[next_idx]
                nums[next_idx] = curr
                curr = temp
                curr_idx = next_idx
                if curr_idx == i:
                    break

    def gcb(self, x: int, y: int) -> int:
        if y > 0:
            return self.gcb(y, x % y)
        else:
            return x


class solution3(rotate_array):
    def rotate(self, nums: list[int], k: int) -> None:
        n = len(nums)
        k %= n
        self.reverse(nums, 0, n - 1)
        self.reverse(nums, 0, k - 1)
        self.reverse(nums, k, n - 1)


    def reverse(self, nums: list[int], start: int, end: int):
        while start < end:
            temp = nums[start]
            nums[start] = nums[end]
            nums[end] = temp


if __name__ == '__main__':
    nums = [1, 2, 3, 4, 5, 6, 7]
    print(nums)
    print(nums[-3:] + nums[:-3])

